﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CopySniffer.UI.Core.Controlers;
using CopySniffer.Search;
using System.Xml;
using System.Xml.Xsl;
using System.IO;
using System.Resources;
using System.Reflection;

namespace CopySniffer.UI.Views.WindowsForms
{
    public partial class EditorView : BaseDockContent, IEditorView
    {
        public EditorView()
        {
            InitializeComponent();
        }

        #region IEditorView Members

        public EditorState State
        {
            get; 
            set;
        }

        public void Cut()
        {
            txtContents.Cut();
        }

        public void Copy()
        {
            txtContents.Copy();
        }

        public void Paste()
        {
            txtContents.Paste();
        }

        public void SearchCopies()
        {
            Controler.SearchCopies();
        }

        public void ShowResults(XmlDocument resultsXml)
        {
            XslCompiledTransform xslt = Controler.GetResultsXslt();
            StringWriter writer = new StringWriter();
            xslt.Transform(new XmlNodeReader(resultsXml), null, writer);
            writer.Flush();
            wbResults.DocumentText = writer.ToString();
            splitContainer.Panel2Collapsed = false;
        }

        #endregion

        #region IView<EditorControler> Members

        public EditorControler Controler
        {
            get;
            set;
        }

        public string UserText
        {
            get { return txtContents.Text; }
            set { txtContents.Text = value; }
        }

        #endregion

        private void rtbContents_TextChanged(object sender, EventArgs e)
        {
            Controler.TreatTextChange();
        }

        #region IEditorView Members


        public void SelectAll()
        {
            txtContents.SelectAll();
        }

        #endregion
    }
}
